﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UI.ServiceReference1;
using Webdiyer.WebControls.Mvc;
namespace UI.Controllers
{
    public class XBKController : Controller
    {
        //
        // GET: /XBK/

        /// <summary>
        /// 人员档案
        /// </summary>
        ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient();

        public ActionResult Renyuandangan(int PageIndx = 1)
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            list = list.ToPagedList(PageIndx, 4);
            return View(list);
        }
        public int UpdateRen(ServiceReference1.Staff m)
        {
            int count = client.updateRen(m);
            return count;
        }
        //提交人员信息
        public ActionResult RenAdd(ServiceReference1.Staff w, HttpPostedFileBase Image_Url)
        {
            if (Image_Url == null)
            {
                return Content("<script>alert('请上传个人照片');location.href='Renyuandangan'</script>");
            }
            string Filepath = Server.MapPath("~/images/");
            if (!Directory.Exists(Filepath))
            {
                Directory.CreateDirectory(Filepath);
            }
            Filepath += Image_Url.FileName;
            Image_Url.SaveAs(Filepath);
            string filePath = "/images/" + Image_Url.FileName;
            w.Image_Url = filePath;
            int count = client.RenAdd(w);
            if (count > 0)
            {
                return Content("<script>alert('添加成功');location.href='Renyuandangan'</script>");
            }
            else
            {
                return Content("<script>alert('添加失败');location.href='FlowerAdd'</script>");
            }
        }
        //人员基本信息修改
        public ActionResult RenUpdae(Staff m, HttpPostedFileBase Image_Url1)
        {
            string Filepath = Server.MapPath("~/images/");
            if (!Directory.Exists(Filepath))
            {
                Directory.CreateDirectory(Filepath);
            }
            Filepath += Image_Url1.FileName;
            Image_Url1.SaveAs(Filepath);
            string filePath = "/images/" + Image_Url1.FileName;
            m.Image_Url = filePath;
            int count = client.updateRen(m);
            if (count > 0)
            {
                return Content("<script>alert('修改成功');location.href='Renyuandangan'</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');location.href='FlowerAdd'</script>");
            }

        }
        //按姓名模糊查询
        public ActionResult cha(string Staff_Name)
        {
            List<ServiceReference1.Staff> list = client.cha(Staff_Name).ToList();
            return View("Renyuandangan", list);
        }
        //奖惩视图
        public ActionResult Jangcheng()
        {
            int i = client.Tiaoshu();
            Session["i"] = i;
            ViewBag.tiaoshu = i;
            return View();
        }
        public int jc()
        {
            int i = client.Tiaoshu();
            return i;
        }
        //奖惩提交
        public ActionResult JangchengAdd(ServiceReference1.奖惩 m)
        {
            int count = client.Jc(m);
            if (count > 0)
            {
                return Content("<script>alert('提交成功');location.href='Jangcheng'</script>");
            }
            else
            {
                return Content("<script>alert('提交失败');location.href='Flower'</script>");
            }
        }

        public ActionResult JL()
        {
            return View();
        }
        //员工查询页面
        public ActionResult YGchauxn()
        {
            return View();
        }
        //按部门查询
        public JsonResult SSS(string BuMen)
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            return Json(list.Where(n => (BuMen != null ? n.BuMen.Contains(BuMen) : true)), JsonRequestBehavior.AllowGet);
        }
        //按姓名查询
        public JsonResult Name(string Staff_Name)
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            return Json(list.Where(n => (Staff_Name != null ? n.Staff_Name.Contains(Staff_Name) : true)), JsonRequestBehavior.AllowGet);
        }
        //按年龄查询
        public JsonResult Ages(int Age, int age1)
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            return Json(list.Where(n => n.Staff_Age >= Age).Where(p => p.Staff_Age <= age1), JsonRequestBehavior.AllowGet);

        }
        //按工资查询
        public JsonResult Money(int Money, int Money1)
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            return Json(list.Where(n => n.Staff_Money > Money).Where(p => p.Staff_Money < Money1), JsonRequestBehavior.AllowGet);

        }
        //查询所有男职员
        public JsonResult Nan()
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            return Json(list.Where(n => n.Staff_Sex == 0), JsonRequestBehavior.AllowGet);
        }
        //查询所有女职员
        public JsonResult NV()
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            return Json(list.Where(n => n.Staff_Sex == 1), JsonRequestBehavior.AllowGet);
        }
        //档案显示
        public ActionResult DangAn()
        {
            List<ServiceReference1.DangAn> lst = client.DangAnIndex().ToList();
            return View(lst);

        }
        //档案详情 反填
        public ActionResult XiangQin(int id)
        {
            ServiceReference1.DangAn lst = client.FT(id);
            return View(lst);
        }
        ///档案添加视图
        public ActionResult DangAnAdd()
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            ViewBag.select = list;

            return View();
        }
        ///档案添加
        public ActionResult DangAnAddto(ServiceReference1.DangAn m)
        {
            int cuont = client.DangAnAdd(m);

            if (cuont > 0)
            {
                return Content("<script>alert('提交成功');location.href='DangAn'</script>");
            }
            else
            {
                return Content("<script>alert('提交失败');location.href='Flower'</script>");
            }
        }
        ///档案删除
        public int DangAnDEL(string id)
        {
            int cuont = client.DangAnDel(id);

            return cuont;
        }
        public ActionResult ContractsIndex()
        {
            List<ServiceReference1.Contracts> lst = client.ContractsIndex().ToList();
            return View(lst);
        }
        public ActionResult ContractsFT(int id)
        {
            ServiceReference1.Contracts m = client.ContractsFT(id);
            return View(m);
        }
        //合同添加页面
        public ActionResult ContractsAdd()
        {
            List<ServiceReference1.Staff> list = client.Ryxinxi().ToList();
            ViewBag.select = list;

            return View();
        }
        //合同添加
        public ActionResult ContractsAddto(ServiceReference1.Contracts m)
        {
            int count = client.ContractsAdd(m);
            if (count > 0)
            {
                return Content("<script>location.href='Contractsindex'</script>");
            }
            else
            {
                return Content("<script>alert('失败喽');location.href='ContractsAdd'</script>");
            }

        }
        //奖惩审批页面
        public ActionResult JcIndex()
        {
            List<ServiceReference1.奖惩> lst = client.Jcindex().ToList();
            return View(lst);
        }
        /// 奖惩审批
        public ActionResult JcShenpi(int id)
        {
            ServiceReference1.奖惩 lst = client.Jcshenpi(id);
            return View(lst);
        }
        /// 奖惩详情
        public ActionResult JcxiangQin(int id)
        {
            ServiceReference1.奖惩 lst = client.Jcshenpi(id);
            return View(lst);
        }
        ///审批通过
        public int TG(int id)
        {
            int count = client.TG(id);
            return count;
        }
        ///审批拒绝
        public int JJ(int id)
        {
            int count = client.JJ(id);
            return count;
        }
        /// 奖惩显示
        public ActionResult JiangchengIndex()
        {
            List<ServiceReference1.奖惩> lst = client.JiangchengIndex().ToList();
            return View(lst);
        }

         
    }
}
